package com.fy56.platform.goodsTracking.web;

import com.fy56.platform.goodsTracking.commons.DateUtil;
import com.fy56.platform.goodsTracking.model.GoodstrackedRecordPublic;
import com.fy56.platform.goodsTracking.model.GoodstrackedRecordTopPublic;
import com.fy56.platform.goodsTracking.model.Jrpt;

import java.util.UUID;

/**
 * Created by XTK on 2016-11-21.
 */
public class GenerateXML {

    public static String Fun_UploadHwgzHydMain(GoodstrackedRecordTopPublic top,Jrpt jrpt) {
        //组货物跟踪信息
        String sCargoXML = "";
        String code;
        if (top.getDatatype().equals("1"))
            code = "05";
        else if (top.getDatatype().equals("2"))
            code = "04";
        else code = "02";
        sCargoXML = sCargoXML + "<?xml version='1.0' encoding='GB2312'?>";
        sCargoXML = sCargoXML + "<Root>";
        sCargoXML = sCargoXML + "<Header>";
        sCargoXML = sCargoXML + "<MessageReferenceNumber>" + UUID.randomUUID() + "</MessageReferenceNumber>"; //系统按GUID规则自动产生
        sCargoXML = sCargoXML + "<DocumentName>普通运输跟踪托运单</DocumentName>"; //单证的中文名称
        sCargoXML = sCargoXML + "<DocumentVersionNumber>V3.1.2</DocumentVersionNumber>";
        sCargoXML = sCargoXML + "<SenderCode>" +  jrpt.getJrptuser()+ "</SenderCode>"; //金融平台用户名
        sCargoXML = sCargoXML + "<MessageSendingDateTime>" + DateUtil.DateNowLong() + "</MessageSendingDateTime>";
        sCargoXML = sCargoXML + "<MessageFunctionCode>" + code + "</MessageFunctionCode>"; //报文功能代码
        sCargoXML = sCargoXML + "</Header>";

        sCargoXML = sCargoXML + "<Body>";
        sCargoXML = sCargoXML + "<ShippingNoteNumber>" + top.getConsignmentbillnumber() + "</ShippingNoteNumber>"; //托运单号：票号
        sCargoXML = sCargoXML + "<OriginalDocumentNumber>" + top.getManualnumber() + "</OriginalDocumentNumber>"; //原始单号：手工单号
        sCargoXML = sCargoXML + "<GoodsSelfNumber>" + top.getGoodsnumber() + "</GoodsSelfNumber>"; //货号
        sCargoXML = sCargoXML + "<InHouseIdentifier>" + jrpt.getOrganizationcode()+ "</InHouseIdentifier>"; //帐套名称前七位
        sCargoXML = sCargoXML + "<ConsignmentDateTime>" + DateUtil.DateNowLong() + "</ConsignmentDateTime>";

        sCargoXML = sCargoXML + "<ConsignorInfo>"; //装货方信息
        sCargoXML = sCargoXML + "<ConsignorCode>" + top.getConsignorcompanycode() + "</ConsignorCode>"; //发货人代码
        sCargoXML = sCargoXML + "<ContactName>" + top.getConsignor() + "</ContactName>"; //发货人
        sCargoXML = sCargoXML + "<TelephoneNumber>" + top.getConsignormobiletelephone() + "</TelephoneNumber>"; //发货人电话
        sCargoXML = sCargoXML + "<CountrySubdivisionName>" + "" + "</CountrySubdivisionName>"; //发货地点的行政区划名称
        sCargoXML = sCargoXML + "<CountrySubdivisionCode>" + "" + "</CountrySubdivisionCode>"; //发货地点的行政区划编码
        sCargoXML = sCargoXML + "<PlaceOfLoading>" + top.getSendcompany() + "</PlaceOfLoading>"; //装货地点：发货地点
        sCargoXML = sCargoXML + "<ResquestedLoadingDateTime>" +  DateUtil.DateNowToLong(top.getConsignmentbilldate())+ "</ResquestedLoadingDateTime>";
        sCargoXML = sCargoXML + "</ConsignorInfo>";

        sCargoXML = sCargoXML + "<ConsigneeInfo>";
        sCargoXML = sCargoXML + "<ConsigneeCode>" + top.getConsigneecompanycode() + "</ConsigneeCode>"; //收货人代码
        sCargoXML = sCargoXML + "<ContactName>" + top.getConsignee() + "</ContactName>"; //收货人
        sCargoXML = sCargoXML + "<TelephoneNumber>" + top.getConsigneemobiletelephone() + "</TelephoneNumber>"; //收货人电话
        sCargoXML = sCargoXML + "<CountrySubdivisionName>" + "" + "</CountrySubdivisionName>"; //中转站的行政区划名称
        sCargoXML = sCargoXML + "<CountrySubdivisionCode>" + "" + "</CountrySubdivisionCode>"; //中转站的行政区划编码
        sCargoXML = sCargoXML + "<GoodsReceiptPlace>" + top.getReceivecompany() + "</GoodsReceiptPlace>"; //收货地点：中转站
        sCargoXML = sCargoXML + "</ConsigneeInfo>";

        sCargoXML = sCargoXML + "<Remark>" + top.getConsignmentbillremark() + "</Remark>"; //备注

        sCargoXML = sCargoXML + "<GoodsInfo>";
        sCargoXML = sCargoXML + "<DescriptionOfGoods>" + top.getGoodsname() + "</DescriptionOfGoods>"; //货物名称
        sCargoXML = sCargoXML + "<TotalNumberOfPackages>" + (int)(top.getTotalnumberofpackages()) + "</TotalNumberOfPackages>"; //总件数
        sCargoXML = sCargoXML + "<PackageTypeCode>" + top.getGoodspack() + "</PackageTypeCode>"; //包装样式
        sCargoXML = sCargoXML + "</GoodsInfo>";

        sCargoXML = sCargoXML + "</Body>";
        sCargoXML = sCargoXML + "</Root>";

        return sCargoXML;
    }

    public static String Fun_GetHwgzMxXml(GoodstrackedRecordPublic sub, Jrpt jrpt) {
        String code;
        if (sub.getDatatype().equals("1"))
            code = "05";
        else if (sub.getDatatype().equals("2"))
            code = "04";
        else code = "02";

        //组货物跟踪信息
        String sCargoXML = "";
        sCargoXML = sCargoXML + "<?xml version='1.0' encoding='GB2312'?>";
        sCargoXML = sCargoXML + "<Root>";

        sCargoXML = sCargoXML + "<Header>";
        sCargoXML = sCargoXML + "<MessageReferenceNumber>" + UUID.randomUUID() + "</MessageReferenceNumber>"; //系统按GUID规则自动产生
        sCargoXML = sCargoXML + "<DocumentName>物流跟踪状态单</DocumentName>"; //单证的中文名称
        sCargoXML = sCargoXML + "<DocumentVersionNumber>V3.1.2</DocumentVersionNumber>";
        sCargoXML = sCargoXML + "<SenderCode>" + jrpt.getJrptuser() + "</SenderCode>"; //金融平台用户名
        sCargoXML = sCargoXML + "<MessageSendingDateTime>" + DateUtil.DateNowLong() + "</MessageSendingDateTime>"; //发送日期时间，格式：YYYYMMDDHHNNSS
        sCargoXML = sCargoXML + "<MessageFunctionCode>" + code + "</MessageFunctionCode>"; //报文功能代码
        sCargoXML = sCargoXML + "</Header>";

        sCargoXML = sCargoXML + "<Body>";
        sCargoXML = sCargoXML + "<ShippingNoteNumber>" +sub.getConsignmentbillnumber() + "</ShippingNoteNumber>"; //托运单号：票号
        sCargoXML = sCargoXML + "<OriginalDocumentNumber>" +sub.getGoodsnumber() + "</OriginalDocumentNumber>"; //原始单号：手工单号
        sCargoXML = sCargoXML + "<GoodsSelfNumber>" + sub.getManualnumber() + "</GoodsSelfNumber>"; //货号
        sCargoXML = sCargoXML + "<InHouseIdentifier>" + jrpt.getOrganizationcode()+ "</InHouseIdentifier>"; //帐套名称前七位
        sCargoXML = sCargoXML + "<TransportStatusCode>" + sub.getTypenum() + "</TransportStatusCode>"; //运输状态代码
        sCargoXML = sCargoXML + "<StatusChangeDateTime>" + DateUtil.DateNowToLong(DateUtil.stringToDate(sub.getSystime())) + "</StatusChangeDateTime>"; //状态变更日期时间，格式：YYYYMMDDHHNNSS
        sCargoXML = sCargoXML + "<PlaceOrLocationIdentification>" + sub.getCreatecompanyname() + "</PlaceOrLocationIdentification>"; //状态变更的地点或位置
        sCargoXML = sCargoXML + "<NameOfPerson>" + sub.getCreateoperator() + "</NameOfPerson>"; //状态变更的操作人（关系人）姓名
        sCargoXML = sCargoXML + "<Remark>" + sub.getInfo() + "</Remark>"; //备注
        sCargoXML = sCargoXML + "</Body>";
        sCargoXML = sCargoXML + "</Root>";

        return sCargoXML;
    }
}
